﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using evt;
using info;
public class ZJHRecordView : MonoBehaviour {

	private GameObject pre3 = null;
	private Transform trans = null;
	void Start () {

		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.SHOW_RECROD,OpenView);
		EventTriggerListener.Get (gameObject).onClick = HideView;
		pre3 = transform.Find ("RecordCell4").gameObject;

		trans = transform.GetChild (1).GetChild (0).GetChild (0);

		int heights = 0;

		for( int i = 0 ; i < UserInfo.records.Count ; i++ ){

			GameObject go = null;
			go = (GameObject)Instantiate (pre3, trans);
			go.transform.SetParent(trans);
			go.GetComponent<RecordCell> ().data = UserInfo.records [i];


			go.transform.localPosition = new Vector3 (0, -99-i*230, 0);

			if(trans.GetComponent<RectTransform> ().sizeDelta.y <= (i*230) ){
				trans.GetComponent<RectTransform> ().sizeDelta = new Vector2 (trans.GetComponent<RectTransform> ().sizeDelta.x,  i*230);
			}
		}

	}

	private void OpenView(object data){
		transform.localPosition = Vector3.zero;
	}

	private void HideView(object data){
		transform.localPosition = new Vector3(10000,0,0);
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
